#coding=utf-8
#@Time:2019/12/9 3:34 PM
#@Author:希哥
#@File:login.py

import sys
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)+'/'+'..'))
from ApiTest import search

'''
    通过数据库查询出用户的user_id/open_id/app_id/union_id/session_key
'''
def userInfo(username):
    user_id = search.search("SELECT id FROM hp_user.user WHERE name = '" + username + "'")
    userInfoTotal = search.search_total("SELECT uw.open_id,uw.app_id,uw.union_id,uwsk.session_key FROM hp_user.user_wx as uw JOIN hp_user.user_weixin_session_key as uwsk on uw.open_id = uwsk.open_id WHERE uw.nick_name = '" + username +"'")
    open_id = userInfoTotal[0][0]
    app_id = userInfoTotal[0][1]
    union_id = userInfoTotal[0][2]
    session_key = userInfoTotal[0][3]
    userInfoMessage = {'user_id':user_id,'open_id':open_id,'app_id':app_id,'union_id':union_id,'session_key':session_key}
    return userInfoMessage

if __name__=='__main__':
    userInfo('Holy')